/* 角色管理模块接口地址 */
import httpInstance from '@/utils/http'
/* TS类型校验 */
import type { resAllRole, records, resAllPermission } from './roleTypes'
/* 统一管理接口 */
enum API {
  /* 获取全部的职位接口 */
  ALLROLE_URL = '/admin/acl/role/',
  /* 新增岗位的接口地址 */
  ADDROLE_URL = '/admin/acl/role/save',
  /* 更新已有的职位 */
  UPDATEROLE_URL = '/admin/acl/role/update',
  /* 获取全部的菜单与按钮的数据 */
  ALLPERMISSTION = '/admin/acl/permission/toAssign/',
  /* 给相应的职位分配权限 */
  SETPERMISTION_URL = '/admin/acl/permission/doAssign/?',
  /* 删除已有的职位 */
  REMOVEROLE_URL = '/admin/acl/role/remove/',
}
/* 获取全部职位接口 */
export const reqGetAllRoleListAPI = (
  page: number,
  limit: number,
  roleName: string,
) => {
  return httpInstance.get<any, resAllRole>(
    API.ALLROLE_URL + `${page}/${limit}?roleName=${roleName}`,
  )
}
/* 添加职位与更新已有职位接口 */
export const reqAddOrUpdateRoleAPI = (data: records) => {
  /* 判断有没有ID 有id的话就发起修改数据请求 没有id的话就发起添加请求 */
  if (data.id) {
    /* 发起修改请求 */
    return httpInstance.put<any, any>(API.UPDATEROLE_URL, data)
  } else {
    /* 添加请求 */
    return httpInstance.post<any, any>(API.ADDROLE_URL, data)
  }
}
/* 获取全部的菜单与按钮的数据 */
export const reqGetAllPermissAPI = (roleId: number) => {
  return httpInstance.get<any, resAllPermission>(API.ALLPERMISSTION + roleId)
} /* 给相应的职位下发权限 */
export const reqSetPermisstionAPI = (roleId: number, permissionId: number[]) =>
  httpInstance.post(
    API.SETPERMISTION_URL + `roleId=${roleId}&permissionId=${permissionId}`,
  )
/* 删除已有的职位 */
export const reqDeletRole = (Id: number) => {
  return httpInstance.delete<any, any>(API.REMOVEROLE_URL + Id)
}
